package servlet;

import domain.GameBean;
import http.ConstansUrl;
import sun.misc.BASE64Encoder;
import util.ByteImageConvert;

import javax.servlet.annotation.WebServlet;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(ConstansUrl.GAME_LIST)
public class GameServlet extends BaseServlet {

    protected String responseJson() throws UnsupportedEncodingException {
        File file = new File("D:/project/demo/src/main/resources/img/test.png");
        byte[] imagePath = ByteImageConvert.image2byte(file.getAbsolutePath());

        GameBean gameBean = new GameBean();
        List<GameBean.DataBean> gameList = new ArrayList<GameBean.DataBean>();
        GameBean.DataBean dataBean = null;
        for (int i = 0; i < 10; i++) {
            dataBean = new GameBean.DataBean(i,"http://www.baidu.com",new BASE64Encoder().encode(imagePath),
                    "飞行棋"+i);
            gameList.add(dataBean);
        }
        gameBean.setData(gameList);
        return mGson.toJson(gameBean);
    }




}

